/*
 * @Author: wupeiwen <javapeiwen2010@gmail.com>
 * @Date: 2022-03-31 11:08:54
 * @LastEditors: wupeiwen <javapeiwen2010@gmail.com>
 * @LastEditTime: 2023-03-21 16:56:41
 * @FilePath: /tea-garden-web/src/util/storeModules/base-list.js
 * @Description: 描述
 */
// import { get } from '@/util/http.js'
import { baseDetail } from '@/util/resData'
export default {
  state: {
    baseList: [],
    loading: {
      baseList: false
    }
  },
  getters: {
    // 通过id获取基地信息
    // baseId - 基地id
    // return - 基地信息
    getBaseInfoById: (state) => (id) => {
      const info = state.baseList.find((item) => {
        return item.id === id
      })
      return info ? info.base_name : ''
    }
  },
  mutations: {
    // 设置通用状态
    setCommonState (state, payload) {
      const { key, value } = payload
      state[key] = value
    },
    // 设置加载状态
    setLoadingState (state, payload) {
      const { key, value } = payload
      state.loading[key] = value
    }
  },
  actions: {
    // 获取基地列表
    async getBaseList ({ commit }) {
      try {
        commit('setLoadingState', { key: 'baseList', value: true })
        // const { data } = await get({ url: '/FarmingBase/BaseDetail' })
        const { data } = baseDetail
        commit('setCommonState', { key: 'baseList', value: data })
      } catch (error) {
        console.log(error)
      }
      commit('setLoadingState', { key: 'baseList', value: false })
    }
  }
}
